import 'package:baselib/utils/image_util.dart';
import 'package:flutter/material.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:get/get.dart';

mixin CommWidgetManager{

  //圆形或者椭圆头像
  static buildCicleImagWidget(
      String imgPath,
      {
        Key key,
        String placeholder,
        double width,
        double height,
        BoxFit fit: BoxFit.cover,
        EdgeInsetsGeometry margin,
        EdgeInsetsGeometry padding,
        Color backgroundColor,
        bool isCircle:true,
        double roundRadius:5,
        Gradient gradient,
      }){
    // print('buildCicleWidget-->imgPath=$imgPath,placeholder=$placeholder');
    return
      isCircle?
      Container(
        margin:margin,
        padding: padding,
        width: width,
        height: height,
        decoration: BoxDecoration(
            color: backgroundColor,
            borderRadius: BorderRadius.all(Radius.circular(width)),
          gradient: gradient
        ),
        child:(!(imgPath??'').startsWith('http'))?
        ClipOval(
          child: Container(
            width: width,
            height: height,
            decoration: BoxDecoration(
              color: backgroundColor,
              borderRadius: BorderRadius.circular(width)
            ),
            child: ImagesUtil.loadAssetImage(
                placeholder??DrawableUtil.instance.icon_default_head,
                width: width,
                height: height,
                fit: BoxFit.fill
            ),
          ),
        ):
        ClipOval(
          child: ImagesUtil.loadNetworkImage(
              imgPath,
              placeholder: placeholder??DrawableUtil.instance.icon_default_head,
              width: width,
              height: height,
              key: key,
              fit: BoxFit.fill
          ),
        ),
      ):Container(
        margin:margin,
        padding: padding,
        width: width,
        height: height,
        child:(!(imgPath??'').startsWith('http'))?
        ClipRRect(
          borderRadius: BorderRadius.circular(roundRadius),
          child: ImagesUtil.loadAssetImage(
              placeholder??DrawableUtil.instance.icon_default_head,
              width: width,
              height: height,
              fit: BoxFit.fill
          ),
        ):
        ClipRRect(
          borderRadius: BorderRadius.circular(roundRadius),
          child: ImagesUtil.loadNetworkImage(
              imgPath,
              placeholder: placeholder??DrawableUtil.instance.icon_default_head,
              width: width,
              height: height,
              key: key,
              fit: BoxFit.fill
          ),
        ),
      )
    ;
  }
  static buildCicleWidget(
      {
        Key key,
        double width,
        double height,
        EdgeInsetsGeometry margin,
        EdgeInsetsGeometry padding,
        Color backgroundColor,
        bool isCircle:true,
        double roundRadius:5,
        Widget child,
        Gradient gradient,
        AlignmentGeometry alignment
      }){
    return
      isCircle?
      Container(
          margin:margin,
          padding: padding,
          width: width,
          height: height,
          alignment: alignment??Alignment.center,
          decoration: BoxDecoration(
              color: backgroundColor,
              borderRadius: BorderRadius.all(Radius.circular(width)),
            gradient: gradient
          ),
          child:
          ClipOval(
            child: child,
          )
      ):Container(
          margin:margin,
          padding: padding,
          width: width,
          height: height,
          alignment: alignment??Alignment.center,
          decoration: BoxDecoration(
              color: backgroundColor,
              borderRadius: BorderRadius.all(Radius.circular(width)),
              gradient: gradient
          ),
          child:
          ClipRRect(
            borderRadius: BorderRadius.circular(roundRadius),
            child: child,
          )
      )
    ;
  }
  static Widget commBar({
    double width,
    double height,
    Color color,
    EdgeInsetsGeometry margin,
    EdgeInsetsGeometry padding,
    double radius,
    bool isDash:false,
    bool isHor:true,
    BoxDecoration decoration,
  }){
    return
//      (isDash)?Container(
//        margin: margin,
//        padding: padding,
//        child: DottedLine(
//          direction: isHor?Axis.horizontal:Axis.vertical,
//          color: color,
//          dashWidth: width,
//          height: height,
//        )
//    ):
      Container(
        width: width??PxUtil.instance.screenWidth,
        height: height??PxUtil.instance.px_1,
        margin: margin,
        padding: padding,
        decoration: decoration??BoxDecoration(
            color: color??ColorUtil.instance.color_f2f2f2,
            borderRadius: BorderRadius.circular(radius??PxUtil.instance.px_0)
        ),
      );
  }
}


